<?php
/**
 * Single error class
 *
 * Based on WP_Error from WordPress and using the Singleton class from Habari
 * @author WordPress
 * @license GNU General Public License (see LICENSE.GPL.txt in the MirrorPress directory)
 */
class Error {
	private $errors = array();

	public function Error($code, $message, $data) {
		$this->errors[$code] = array(
			'message' => $message,
			'data' => $data
		);
	}

	public function get_codes() {
		if( empty($this->errors) )
			return array();

		return array_keys($this->errors);
	}

	public function get_messages() {
		if( empty($this->errors) )
			return array();

		$messages = array();

		foreach($this->errors as $code => $error) {
			$messages[$code] = $error['message'];
		}

		return $messages;
	}

	public function get_data() {
		if( empty($this->errors) )
			return array();

		$data = array();

		foreach($this->errors as $code => $error) {
			$data[$code] = $error['data'];
		}

		return $data;
	}
}